package cn.easybuy.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.easybuy.dao.BaseDao;
import cn.easybuy.dao.OrderDetailDao;
import cn.easybuy.entity.OrderDetail;
import cn.easybuy.entity.Product;

public class OrderDetailDaoImpl extends BaseDao implements OrderDetailDao {

	@Override
	public List<Object> getDetailsList(int orderId) {
		String sql = "select p.name,p.fileName,o.quantity,o.cost from easybuy_order_detail o,easybuy_product p where o.productId=p.id and o.orderId=?";
		List<Object> list = new ArrayList<Object>();
		ResultSet rs = this.exxcuteQuery(sql, orderId);
		try {
			while (rs.next()) {
				OrderDetail orDetail = new OrderDetail();
				Product product = new Product();
				product.setName(rs.getString(1));
				product.setFileName(rs.getString(2));
				orDetail.setQuantity(rs.getInt(3));
				orDetail.setCost(rs.getFloat(4));
				list.add(product);
				list.add(orDetail);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.closeAll(connection, pstmt, rs);
		}
		return list;
	}

}
